//
//  WBVIsitorController.swift
//  weiboD
//
//  Created by gao2015 on 2016/12/2.
//  Copyright © 2016年 gao2015. All rights reserved.
//

import UIKit

class WBVIsitorController: UITableViewController {

    //设置访客默认是未登录状态
    //通过userAccount加载沙盒数据,若没有加载到isLogin = false 未登录状态 ，反之登录
    let isLogin : Bool = WBUserAccoutViewModel.shareUserAccout.userAccount != nil
    //提供一个访客视图,子类继承可能用到
    var visitorView : WBVisitorView?
    
    override func loadView() {
   
        if isLogin == false {//未登录状态
            visitorView = WBVisitorView()
            //        visitorView.backgroundColor = UIColor.brown
            view = visitorView
            //设置
            visitorView?.callBack = {
            //第三方登录新浪微博
                self.loadOAuth()
            }
            //统一设置导航栏
            setupNavUI()

            //未登录
        }else{
            super.loadView()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }

    func setupNavUI(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(regist))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: #selector(login))

    }
    @objc private func regist(){
        
        print("注册")
    }
    @objc private func login(){
        print("登录")
        
    }
    
    //MARK:1.第三方登录新浪微博的方法
    private func loadOAuth(){
        let oAuthVc = WBAuthController()
        //绑定导航控制器
        let nav = WBNavController(rootViewController: oAuthVc)
        present(nav, animated: true, completion: nil)

    }
    
}
